if File.exist?('../.env')
  open('../.env', 'r').readlines.each do |l|
    kv = l.split('=')
    ENV[kv[0]] = kv[1].chomp
  end
end


lane :build do
    addKeyChain

    build_app(
      workspace: "V2rayU.xcworkspace",
      scheme: "V2rayU",
      export_method: "development",
      skip_package_pkg: "false",
      clean: "true",
      derived_data_path: "./build_derived_data"
    )
end

lane :upload do
    appcenter_upload(
        api_token: ENV["API_TOKEN"],
        owner_name: "yanue",
        app_name: "V2rayU",
        build_number: ENV["BUILD_NUMBER"],
        version: ENV["VERSION"],
        app_os: 'macOS',
        file: "./Build/V2rayU-64.dmg",
        dsa_signature: ENV["dsa_signature"]
    )
end

lane :sparkle do

end

lane :addKeyChain do
  if is_ci?
    
    puts("create custom keychain")

    delete_keychain(
      name: "v2rayUBuild"
    ) if File.exist? File.expand_path("~/Library/Keychains/v2rayUBuild-db")

    create_keychain(
      name: "v2rayUBuild",
      default_keychain: false,
      unlock: true,
      timeout: 3600,
      lock_when_sleeps: false,
      password: "password"
    )
    
    import_certificate(
      certificate_path: "Build/sign.p12",
      keychain_name:"v2rayUBuild",
      keychain_password:"v2rayUBuild",
      certificate_password:""
    )
  end
end
